package com.xiaoai.io.bio4;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author
 * @Date 2021-09-06 01:04
 */
public class HandlerSockerServerPool {

    private ExecutorService executorService;

    // 创建类对象时初始化线程池对象

    /**
     *
     * @param maxThreadNum
     * @param queueSize
     */
    public HandlerSockerServerPool(int maxThreadNum, int queueSize){
        /**
         * ThreadPoolExecutor(int corePoolSize,
         *                               int maximumPoolSize,
         *                               long keepAliveTime,
         *                               TimeUnit unit,
         *                               BlockingQueue<Runnable> workQueue)
         */
        executorService = new ThreadPoolExecutor(3,maxThreadNum,120, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(queueSize));

    }

    public void execute(Runnable target){
        executorService.execute(target);
    }

}
